package com.cbtx.module.common.vm

import android.app.Application
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.cbtx.module.base.vm.BaseVM
import com.cbtx.module.common.R
import com.cbtx.module.common.bean.GoodsEntity
import com.cbtx.module.common.http.HttpUrlManager
import com.txcb.lib.base.utils.DeviceUtil
import com.txcb.lib.base.utils.ZxingUtils

class TreasureDetailVM(application: Application) : BaseVM(application) {


    var mData: GoodsEntity.DataBean.ListBean? = null
    var mPriceStr = ""

     val mImageList : MutableList<String>  = ArrayList()

    fun getIntent(intent: Intent) {

        mData = intent.getSerializableExtra("goodsBean") as GoodsEntity.DataBean.ListBean?


        resetData()
    }

    fun getQrBitmap(): Bitmap {

        val color = mApplication.resources.getColor(R.color.c_e0c28f)
        val bgColor = mApplication.resources.getColor(R.color.c_f8f8f8)
        val logoBitmap =
            BitmapFactory.decodeResource(mApplication.resources, R.drawable.ic_logo_qr_code)
        val url = "${HttpUrlManager.DEVICE_WXQRCODE}${DeviceUtil.getSerialNumber(mApplication)}"

        return ZxingUtils.createQRCodeWithLogo(url, 148, logoBitmap, 0, color, bgColor)
    }


    fun resetData( ) {
        mData?.category = "藏品类别：${mData?.category}"
        mData?.years = "藏品年代：${mData?.years}"

        mPriceStr = "${mData?.insurancePrice}"

        mImageList.clear()

        mImageList.addAll(mData?.imageList!!)
    }
}